﻿using Shop.Api.Models;
using Shop.Data.Business;
using Shop.Data.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
//La tabla Factura esta echo por Roger ticona nina

namespace Shop.Api.Controllers
{
    public class FacturaController : ApiController
    {
        // GET api/<controller>
        public IEnumerable<FacturaModel> Get()
        {
            //return new string[] { "value1", "value2" };
            return FacturaBusiness.GetListByFilter("").Select(

                t => new FacturaModel
                {
                    IdFactura = t.IdFactura,
                    DniCliente = t.DniCliente,
                    RucCliente = t.RucCliente,
                    SubTotal = t.SubTotal,
                    Igv = t.Igv,
                    Total = t.Total,
                    FechaFactura = t.FechaFactura,

                    
                });
        }

        // GET api/<controller>/5
        public FacturaModel Get(Guid id)
        {
            //return "asdasdsadsa";  
            Factura p = FacturaBusiness.GetById(id);
            return new FacturaModel
            {
                IdFactura = p.IdFactura,
                DniCliente = p.DniCliente,
                RucCliente = p.RucCliente,
                SubTotal = p.SubTotal,
                Igv = p.Igv,
                Total = p.Total,
                FechaFactura = p.FechaFactura,
            };
        }

        // POST api/<controller>
        public FacturaModel Post([FromBody]FacturaModel model)
        {
            //return "Mi post";
            Factura p = FacturaBusiness.Create(new Factura
            {

                DniCliente = model.DniCliente,
                RucCliente = model.RucCliente,
                SubTotal = model.SubTotal,
                Igv = model.Igv,
                Total = model.Total,
                FechaFactura = model.FechaFactura,
            });
            return new FacturaModel
            {
                IdFactura = p.IdFactura,
                DniCliente = p.DniCliente,
                RucCliente = p.RucCliente,
                SubTotal = p.SubTotal,
                Igv = p.Igv,
                Total = p.Total,
                FechaFactura = p.FechaFactura,

            };
        }

        // PUT api/<controller>/5
        public FacturaModel Put(Guid IdFactura, [FromBody]FacturaModel model)
        {
            //return "Mi put";
            Factura p = FacturaBusiness.Update(new Factura
            {
                IdFactura = model.IdFactura,
                DniCliente = model.DniCliente,
                RucCliente = model.RucCliente,
                SubTotal = model.SubTotal,
                Igv = model.Igv,
                Total = model.Total,
                FechaFactura = model.FechaFactura,
            });
            return new FacturaModel
            {

                IdFactura = p.IdFactura,
                DniCliente = p.DniCliente,
                RucCliente = p.RucCliente,
                SubTotal = p.SubTotal,
                Igv = p.Igv,
                Total = p.Total,
                FechaFactura = p.FechaFactura,

            };
        }

        // DELETE api/<controller>/5
        public void Delete(Guid IdFactura)
        {
            FacturaBusiness.Delete(IdFactura);
        }
    }
}